//package com.cxb;
//
//import org.apache.http.*;
//import org.apache.http.client.config.RequestConfig;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClientBuilder;
//import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
//import org.apache.http.util.EntityUtils;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
//
//public class HttpUtilsForSubmitPdf {
//
//
//    private static final ObjectMapper objectMapper = new ObjectMapper();
//
//    //使用当前配置
//    public static CloseableHttpClient getHttpClient(PoolingHttpClientConnectionManager manager, int socketTimeout) {
//        RequestConfig requestConfig = RequestConfig.custom()
//                .setConnectTimeout(3000) // 建立tcp握手的时间
//                .setConnectionRequestTimeout(3000) // 从连接池等待获取连接的时间
//                .setSocketTimeout(socketTimeout).build(); // 等待服务器返回数据的时间
//        manager.setDefaultMaxPerRoute(300);  //设置当前路由也就是域名同时最大的连接数
//        manager.setMaxTotal(300); //设置最大的连接数
//        return HttpClientBuilder.create().evictExpiredConnections().evictIdleConnections(3L, TimeUnit.SECONDS) //默认3秒回收空闲连接
//                .setConnectionManager(manager)
//                .setDefaultRequestConfig(requestConfig)
//                .setConnectionTimeToLive(1L, TimeUnit.SECONDS).build();
//    }
//
//
//    public static JSONObject post(String url, Object params, Map<String, String> headers, Integer socketTimeoutTime) {
//
//
//        PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
//
//        CloseableHttpClient httpClient = getHttpClient(manager, socketTimeoutTime);
//        HttpPost post = new HttpPost(url);
//        post.setHeaders(getHeaders(headers));
//        StringEntity stringEntity;
//        try {
////            stringEntity = new StringEntity(objectMapper.writeValueAsString(params));
////            stringEntity.setContentEncoding("UTF-8");
////            stringEntity.setContentType("application/json");
//            stringEntity = new StringEntity(objectMapper.writeValueAsString(params),"UTF-8");
//            stringEntity.setContentEncoding("identity");
//            //stringEntity.setContentEncoding("UTF-8");
//            stringEntity.setContentType("application/json");
//        } catch (Exception e) {
//            log.error("HttpClientUtil param format  post error!", e);
//            throw new TezignException("HttpClientUtil param format  post error!");
//        }
//        post.setEntity(stringEntity);
//
//        JSONObject resultBean = null;
//        try (CloseableHttpResponse executeResult = httpClient.execute(post)) {
//            log.info("请求返回结果：" + executeResult.toString());
//            String resultJson;
//            if (executeResult.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) {
//                resultJson = EntityUtils.toString(executeResult.getEntity(), "UTF-8");
//                resultBean = JSON.parseObject(resultJson, JSONObject.class);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.error("HttpClientUtil post error!", e);
//            throw new TezignException("HttpClientUtil post error!");
//        }
//        log.info("HttpClientUtil post resultBean:{}", JSON.toJSONString(resultBean));
//        return resultBean;
//    }
//
//    private static Header[] getHeaders(Map<String, String> headers) {
//        if (headers == null) {
//            return new Header[]{};
//        }
//        headers.putAll(getDefaultHeaders());
//        return headers.entrySet().stream().map(val -> new Header() {
//            @Override
//            public HeaderElement[] getElements() throws ParseException {
//                return new HeaderElement[0];
//            }
//
//            @Override
//            public String getName() {
//                return val.getKey();
//            }
//
//            @Override
//            public String getValue() {
//                return val.getValue();
//            }
//        }).toArray(Header[]::new);
//    }
//
//    public static Map<String, String> getDefaultHeaders() {
//        Map<String, String> headers = Maps.newHashMap();
//        headers.put("Content-Type", "application/json;charset=UTF-8");
//        headers.put("Connection", "keep-alive");
//        return headers;
//    }
//
//    public static void main(String[] args) {
//        //String submitUrl = "http://localhost:8080/metadata/ui/pdf/generalProductPdf/test/public";
//        String submitUrl = "http://192.168.2.43:3001/solution-node/html-to-files/pdf";
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("code", "code");
//        jsonObject.put("message", "峰会停息");
//        jsonObject.put("result", "峰会停息");
//        jsonObject.put("traceId", "峰会停息");
//        MetadataUiPdfSubmitNodeBean metadataUiPdfSubmitNodeBean = new MetadataUiPdfSubmitNodeBean();
//        List<MetadataUiPdfSubmitNodeDetailBean> submitDataList = new ArrayList<>();
//        MetadataUiPdfSubmitNodeDetailBean metadataUiPdfSubmitNodeDetailBean = new MetadataUiPdfSubmitNodeDetailBean
//                ("t29", JSON.toJSONString(jsonObject), "t1", 1234L, 5L);
//
//        MetadataUiPdfSubmitNodeDetailBean metadataUiPdfSubmitNodeDetailBean1 = new MetadataUiPdfSubmitNodeDetailBean
//                ("t29", JSON.toJSONString(jsonObject), "t2", 1234L, 5L);
//
//        submitDataList.add(metadataUiPdfSubmitNodeDetailBean);
//        submitDataList.add(metadataUiPdfSubmitNodeDetailBean1);
//        metadataUiPdfSubmitNodeBean.setPdfInfoList(submitDataList);
//        JSONObject post = post(submitUrl, metadataUiPdfSubmitNodeBean, new HashMap<>(), 3000);
//        log.info(post == null ? "返回为空" : post.toJSONString());
//
//    }
//}
